{{#extends @html/widgets/node_widget.html}}

{{:widget_title}}{{?widget.content.comments}}{{?widget.title}}{{widget.title}}{{?:}}Комментарии{{/?}}{{/?}}{{/:widget_title}}

{{:widget_div_name}}newcomments{{/:widget_div_name}}

{{:widget_body}}
	{{!connect "screen/widgets/wg-newcomments.css"}}
	{{?widget.content.comments}}

		{{?widget.content.comments}}
			<div class="list-">
			{{!for widget.content.comments as="comments" do=@:comments_list}}{{:comments_list}}
				<div class="date-">{{comments.0.date}}</div>
				{{!for comments as="data" do=@:comments_item}}{{:comments_item}}
				<div class="item-">
					<div class="meta-"><a href="{{/}}{{data.community.community_url}}/{{data.item_oid}}" class="parent-">&laquo;{{data.item.title}}&raquo;</a></div>
					<div class="comment-"><a href="{{/}}members/{{data.user.oid}}" class="user-">{{data.user.login}}</a> <span class="timelock-">в {{data.comment_time}}:</span>
					<a href="{{/}}{{data.community.community_url}}/{{data.item_oid}}?parent_oid={{data.id}}&submit=1">{{data.text}}</a></div>
				</div>
				{{/:comments_item}}
			{{/:comments_list}}
			</div>
		{{?:}}
			<p>Нету комментариев.</p>
		{{/?}}
	{{/?}}
{{/:widget_body}}


{{:settings}}
<div class="popup-widgets" id="settings_container">
	<form action="" id="settingsform">
	<input type="hidden" name="widget_id" value="{{settings.id}}" id="widget_id" />
	<h2 class="title-">Последние комментарии</h2>
	<div class="content-" style="height: 400px; overflow: auto;">
		<fieldset class="fieldset- header- text-">
			<label>Заголовок</label>
			<input type="text" name="title" value="{{settings.title}}" />
			<div class="comment-">Не более 100 символов</div>
		</fieldset>
		<fieldset class="fieldset- header- text-">
			<label>Количество комментариев</label>
			<input type="text" name="commentscount" value="{{settings.commentscount}}" />
		</fieldset>
		<fieldset class="fieldset- header- text-">
			<label>Комментарии:</label>
			<input type="radio" style="display:inline;width: 24px;" id="from_node" name="from" value="node"{{?'node'==settings.from || !settings.from}} checked="checked"{{/?}} />
			<label for="from_node" style="display:inline; margin-left: 24px;"> всего узла</label><br />
			<input type="radio" style="display:inline;width: 24px;" id="from_community" name="from" value="community"{{?'community'==settings.from}} checked="checked"{{/?}} /> 
			<label for="from_community" style="display:inline; margin-left: 24px;">только из сообществ</label><br />
			{{!for settings.community do=@:community}}
		</fieldset>
	</div>
	{{@:settingsbutton}}
	</form>
	<script>
	jQuery("#from_node").bind("click", function(){
		setCheckBoxRights()
	});
	jQuery("#from_community").bind("click", function(){
		setCheckBoxRights()
	});
	jQuery().ready( function(){
		setCheckBoxRights();
	});
	
	function setCheckBoxRights() {
		var from_node = jQuery("#from_node").get(0).checked;
		jQuery("#settings_container").find("input.commcheck-").each(function(){
			if ( from_node ) {
				this.disabled = true;
				this.checked = false;
			} else {
				this.disabled = false;
			}
		});
	}
	
	function toggleGroup( parentItem, groupName ) {
		var setCheck = parentItem.checked;
		jQuery("#settings_container").find("input." + groupName).each(function(){
			this.checked = setCheck;
		});
	}
	
	function testCheckParent( childItem, parentOID, groupName ) {
		var setCheck = childItem.checked;
		
		if ( setCheck ) {
			jQuery("#community" + parentOID).get(0).checked = true;
		} else {
			var needClean = true;
			jQuery("#settings_container").find("input." + groupName).each(function(){
				if ( this.checked ) {
					needClean = false;
				}
			});
			
			if ( needClean ) {
				jQuery("#community" + parentOID).get(0).checked = false;
			}
		}
	}
	</script>
</div>
{{/:settings}}
